package com.yw.wanandroid.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.yw.wanandroid.R
import com.yw.wanandroid.databinding.RvItemTopArticleBinding
import com.yw.wanandroid.model.HomeTopArticleModel

class HomeTopAdapter(var list: ArrayList<HomeTopArticleModel>) :
    RecyclerView.Adapter<HomeTopAdapter.HomeViewItemTopHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeViewItemTopHolder {
        return HomeViewItemTopHolder(
            DataBindingUtil.inflate(
                LayoutInflater.from(parent.context),
                R.layout.rv_item_top_article,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: HomeViewItemTopHolder, position: Int) {
        holder.binding.bean = list[position]
    }

    override fun getItemCount(): Int {
        return list.size
    }

    class HomeViewItemTopHolder(var binding: RvItemTopArticleBinding) :
        RecyclerView.ViewHolder(binding.root)
}